package com.wgj.android.utils.fonat;

import android.content.Context;
import android.graphics.Typeface;

import com.jiaai.xui.icon.typeface.IIcon;
import com.jiaai.xui.icon.typeface.ITypeface;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;

/**
 * Created by Administrator on 2017/8/5.
 */

public class IconFonat implements ITypeface {
    private static final String TTF_FILE = "wgj_iconfont.ttf";

    private static Typeface typeface = null;

    private static HashMap<String, Character> mChars;

    @Override
    public IIcon getIcon(String key) {
        return IconFonat.Icon.valueOf(key);
    }

    @Override
    public HashMap<String, Character> getCharacters() {
        if (mChars == null) {
            HashMap<String, Character> aChars = new HashMap<String, Character>();
            for (IconFonat.Icon v : IconFonat.Icon.values()) {
                aChars.put(v.name(), v.character);
            }
            mChars = aChars;
        }

        return mChars;
    }

    @Override
    public String getMappingPrefix() {
        return "faw";
    }

    @Override
    public String getFontName() {
        return "FontAwesome";
    }

    @Override
    public String getVersion() {
        return "4.5.0.1";
    }

    @Override
    public int getIconCount() {
        return mChars.size();
    }

    @Override
    public Collection<String> getIcons() {
        Collection<String> icons = new LinkedList<String>();

        for (IconFonat.Icon value : IconFonat.Icon.values()) {
            icons.add(value.name());
        }

        return icons;
    }

    @Override
    public String getAuthor() {
        return "东莞佳爱";
    }

    @Override
    public String getUrl() {
        return "http://www.iconfont.cn/manage/index?manage_type=myprojects&projectId=443790";
    }

    @Override
    public String getDescription() {
        return "直播间iconfont 图标库整合";
    }

    @Override
    public String getLicense() {
        return "SIL OFL 1.1";
    }

    @Override
    public String getLicenseUrl() {
        return "http://scripts.sil.org/OFL";
    }

    @Override
    public Typeface getTypeface(Context context) {
        if (typeface == null) {
            try {
                typeface = Typeface.createFromAsset(context.getAssets(),  "iconfont/"+TTF_FILE);
            } catch (Exception e) {
                return null;
            }
        }
        return typeface;
    }

    public static enum Icon implements IIcon {
        my_select('\ue601'),
        my_on('\ue600'),
        msg_select('\ue63d'),
        msg_on('\ue606'),
        home_select('\ue623'),
        home_on('\ue626'),
        shop_on('\ue604'),
        shop_select('\ue60f'),
        icon_zijin('\ue603'),
        icon_wallet('\ue605'),
        icon_yongjin('\ue602'),
        icon_pinpai1('\ue619'),
        icon_guanyu('\ue638'),
        icon_banben('\ue612'),
        icon_haoyouguanli('\ue63e'),
        icon_qunfa('\ue842'),
        icon_jiance('\ue62b'),
        icon_yuechi('\ue850'),
        icon_group('\ue67d'),
        icon_hongbao('\ue792'),
        icon_haoyoutuijian('\ue648'),
        icon_qingli('\ue64e'),
        icon_shangcheng('\ue607'),
        icon_gengduo('\ue63f'),
        icon_ceshi('\ue608'),
        icon_i('\ue609'),
        icon_dizhi('\ue60a'),
        icon_fuwu1('\ue616'),
        icon_fuwu('\ue60b'),
        icon_wuxinyongqia('\ue86b'),
        icon_fenxiang('\ue84f'),
        icon_lianjie('\ue666'),
        icon_pengyouquan('\ue7d3'),
        icon_weixin('\ue61f'),
        icon_qq('\ue654'),
        icon_shengnannv('\ue610'),
        icon_qqkongjian('\ue63b'),
        icon_live('\ue6e2'),
        icon_pinpai('\ue615'),
        icon_qiandao('\ue618'),
        //icon_hongbao('\ue620'),
        icon_guanggao('\ue647');
        char character;

        Icon(char character) {
            this.character = character;
        }

        public String getFormattedName() {
            return "{" + name() + "}";
        }

        public char getCharacter() {
            return character;
        }

        public String getName() {
            return name();
        }

        // remember the typeface so we can use it later
        private static ITypeface typeface;

        public ITypeface getTypeface() {
            if (typeface == null) {
                typeface = new IconFonat();
            }
            return typeface;
        }
    }
}
